package com.smarth.zhizulian.jsinter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.webkit.JavascriptInterface;

import com.smarth.zhizulian.activity.LoginActivity;
import com.smarth.zhizulian.bean.user.DiscipleIndex;
import com.smarth.zhizulian.bean.video.VideoShare;
import com.smarth.zhizulian.http.KumaHttp;
import com.smarth.zhizulian.http.observer.PageObserver;
import com.smarth.zhizulian.http.observer.ProgressObserver;
import com.smarth.zhizulian.http.utils.RxCompos;
import com.smarth.zhizulian.utils.KumaDialogFactory;
import com.smarth.zhizulian.utils.KumaLog;
import com.smarth.zhizulian.utils.KumaToast;
import com.smarth.zhizulian.utils.ShareUtils;
import com.smarth.zhizulian.utils.UserUtils;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * Created by 18865 on 2018/1/26.
 */

public class JSDrawInterface {
    private Context mContext;

    public JSDrawInterface(Context context) {
        this.mContext = context;
    }

    @JavascriptInterface
    public void share() {
        //朋友圈
        if (UserUtils.isLogin()) {
//            KumaHttp.getService().videoShare("" + relationId)
//                    .compose(RxCompos.<VideoShare>getBELoginCompos())
//                    .subscribe(new ProgressObserver<VideoShare>(mContext) {
//                        @Override
//                        public void onNext(VideoShare videoShare) {
//                            ShareUtils.shareToMomentWebPage(videoShare.getTitle(), videoShare.getDesc(), videoShare.getImage(), videoShare.getUrl(), new PlatformActionListener() {
//                                @Override
//                                public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
//                                    KumaToast.show(mContext, "分享成功");
//                                }
//
//                                @Override
//                                public void onError(Platform platform, int i, Throwable throwable) {
//                                    KumaToast.show(mContext, "分享失败");
//                                }
//
//                                @Override
//                                public void onCancel(Platform platform, int i) {
//                                    KumaToast.show(mContext, "取消分享");
//                                }
//                            });
//                        }
//                    });
            KumaHttp.getService().discipleIndex()
                    .compose(RxCompos.<DiscipleIndex>getBELoginCompos())
                    .subscribe(new ProgressObserver<DiscipleIndex>(mContext) {
                        @Override
                        public void onNext(final DiscipleIndex discipleIndex) {
                            KumaDialogFactory.buildShareDialog((Activity) mContext, new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    ShareUtils.shareForAddFriends(mContext, discipleIndex, Wechat.NAME);
                                }
                            }, new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    ShareUtils.shareForAddFriends(mContext, discipleIndex, WechatMoments.NAME);
                                }
                            }, new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    ShareUtils.shareForAddFriends(mContext, discipleIndex, QQ.NAME);
                                }
                            }).show();
                        }
                    });
        } else {
            LoginActivity.open(mContext);
        }
    }

}
